import request from '../utils/request';
import code from '../utils/k';

export async function login(phone, password, openid) {
  return await request('/login', { method: 'post', body: { phone, password, openid } });
}

export async function logout() {
  return await request('/logout', { method: 'post' });
}

export async function resetPassword(id, oldPassword, password, confirmPassword) {
  return await request(`/resetPwd/${id}`, { method: 'put', body: { oldPassword, password, confirmPassword } });
}

export function me() {
  return request('/me');
}

export function checkShop(shopId) {
  return request('/checkShopStatus', { params: { shopId } });
}

export function findPassword(phone, code, password) {
  return request(`/findPwd/${phone}`, { method: 'put', body: { code, password } });
}

export function getCode(phone) {
  return request('/smsVerifyCode', { method: 'post', body: { d: code({ phone }) } });
}

export function getSalesman(params) {
  const { shopId, branchNo } = params;
  if (branchNo) {
    return request(`/shop/${shopId}/branch/${branchNo}/saleMan`, { params });
  }

  return request(`/shop/${shopId}/saleMan`, { params });
}

export function updateUser(id, body) {
  return request(`/users/${id}`, {
    method: 'put',
    body,
  });
}

export function getInfo(code) {
  return request(`../wx/getInfo`, {
    params: {
      code,
    },
  });
}
